<template>
    <div class="bg-container">
        <div class="login-form">
            <div class="login-box">
              <div class="login-title">公寓管理系统</div>
                <el-form label-width="80px" class="login-input">
                    <el-form-item label="账号" prop="userId">
                        <el-input type="text" placeholder="请输入账号" v-model="userId" />
                    </el-form-item>
                    <el-form-item label="密码" prop="passWord">
                        <el-input type="password" placeholder="请输入密码" v-model="passWord" />
                    </el-form-item>
                    <el-form-item>
                        <el-button type="primary" style="float:right" @click="onSubmit">登录</el-button>
                    </el-form-item>
                </el-form>
            </div>
        </div>
        <div class="footer">
            <div class="copyright">
                <span>Copyright &copy; 2021 徐丢丢有限公司</span>
            </div>
        </div>
    </div>
</template>
<script>
import { setToken, setUserId ,setUserName,setPermissions} from "@/utils/auth";
import request from "@/utils/request";
export default {
  name: "login",
  data() {
    return {
      userId: "201801011368",
      passWord: "014522",
      // userName:""
    };
  },
  methods: {
    onSubmit() {
      var userId = this.userId;
      var passWord = this.passWord;
      // var userName = this.userName;
      request({
        url: "/api/loginInfo/login",
        method: "post",
        data: {
          userId,
          passWord,
          // userName
        }
      }).then(res => {
        if (res.status == 200) {
          this.$message({
            message: "恭喜你，登录成功",
            type: "success"
          });
          // console.log(res.userName);
          setToken(res.token);
          setUserId(res.userId);
          setUserName(res.userName);
          setPermissions(res.permissions);
          if(res.permissions=="1" || res.permissions=="2"){
             this.$router.push("hello");
          }
          else if(res.permissions=="4"){
            this.$router.push("studentServer");
          }else{
            this.$router.push("hello");

          }
        }else{
          this.$message({
            message: "账号密码错误，请重新输入",
            type: "error"
          });
        }
        
      });
    }
  }
};
</script>
<style scoped>
.el-form-item__label{
  color: #fff;
}
.bg-container {
  width: 100%;
  height: 900px;
  overflow: hidden;
  margin: 0;
  background-image: url('../../assets/login_bg.jpg');
  background-size:100% 100%;
}
.footer {
  position: absolute;
  bottom: 0;
  width: 100%;
  margin: 0 auto;
  height: 30px;
  line-height: 20px;
  padding-top: 5px;
  padding-bottom: 5px;
}
.footer .copyright {
  font-size: 12px;
  text-align: center;
  width: 100%;
  /* color: #fff; */
  opacity: 0.5;
}
.login-form {
  position: absolute;
  left: 50%;
  top: 35%;
  transform: translate(-50%, -50%);
}
/* h2 {
    color: #fff;
  } */
  .login-box{
    background-color: #ecf5ffe0;
    box-shadow: 0 0 25px #909399;
    border: 1px solid #dcdfe6;
    border-radius: 5px;
    -webkit-border-radius: 5px;
    -moz-border-radius: 5px;
  }
.login-input {
  width: 350px;
  margin-top: 70px;
  padding-right: 40px;
}
.login-title{
  width: fit-content;
  position: absolute;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 20px;
  font-weight: 700;
  color: rgb(254,139,51);
  
}
</style>